package com.wushi.lenovo.asia5b.app_ui.other;

import android.content.Context;
import android.support.v4.widget.NestedScrollView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mvp.base.BaseDialog;
import com.wushi.lenovo.asia5b.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by zhangyuncai on 2020/3/3.
 */
public class OrderPackBeforeNoticeDialog extends BaseDialog {

    public String title = null;
    public String content = null;
    public boolean contentHtml=false;
    public String ok = null;
    public String cancel = null;
    @BindView(R.id.iv_cancelsure_ok)
    ImageView iv_cancelsure_ok;
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_shopcar_dialogcontent)
    TextView tv_shopcar_dialogcontent;
    @BindView(R.id.nsv_shopcar_dialogcontent)
    NestedScrollView nsv_shopcar_dialogcontent;
    @BindView(R.id.bt_shopcar_dialogok)
    Button bt_shopcar_dialogok;
    @BindView(R.id.bt_shopcar_dialogcancel)
    Button bt_shopcar_dialogcancel;
    @BindView(R.id.ll_shopcar_container)
    LinearLayout ll_shopcar_container;
    @BindView(R.id.web_shopcar)
    WebView webView;

    public OrderPackBeforeNoticeDialog(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_orderpack_before_notice;
    }

    @Override
    protected void initView() {
        if (!TextUtils.isEmpty(title)) {
            tv_title.setText(title);
        }
        if (!TextUtils.isEmpty(content)) {
            //内容
            if(contentHtml) {
                ll_shopcar_container.setVisibility(View.VISIBLE);
                webView.getSettings().setJavaScriptEnabled(false);
                webView.loadData(content, "text/html", "utf-8");
            }else {
                tv_shopcar_dialogcontent.setText(content);
            }
        }
        if (!TextUtils.isEmpty(ok)) {
            bt_shopcar_dialogok.setText(ok);
        }
        if (!TextUtils.isEmpty(cancel)) {
            bt_shopcar_dialogcancel.setText(cancel);
        }
    }

    @OnClick({
            R.id.bt_shopcar_dialogok,
            R.id.bt_shopcar_dialogcancel,
            R.id.iv_cancelsure_ok
    })
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_shopcar_dialogok:
                if (callBack != null) {
                    callBack.callback(true);
                }
                dismiss();
                break;
            case R.id.iv_cancelsure_ok:
                dismiss();
                break;
            case R.id.bt_shopcar_dialogcancel:
                if (callBack != null) {
                    callBack.callback(false);
                }
                dismiss();
                break;
        }
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected int getWidthStyle() {
        return getScreenWidth(0.9f);
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }
}
